package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.Result;
import com.yyb.domain.SysMenu;
import com.yyb.dto.SysMenuAddDTO;
import com.yyb.dto.SysMenuUpdateDTO;
import com.yyb.enums.BusinessType;
import com.yyb.service.SysMenuService;
import com.yyb.vo.RouterVO;
import com.yyb.vo.SysMenuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述: [菜单管理接口]
 * 
 * 
 */
@RestController
@RequestMapping("sysMenu")
@Tag(name = "菜单管理接口")
public class SysMenuController extends BaseController{

    @Resource
    private SysMenuService sysMenuService;

    /**
     * 查询所有菜单权限
     *   GET http://127.0.0.1:8080/sysMenu/listMenu
     *   接口ID：148742206
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742206
     */
    @Operation(summary = "查询所有菜单权限数据")
    @GetMapping("listMenu")
    @AppPermission("system:menu:query")
    public Result<List<SysMenuVO>> listMenu(){
        List<SysMenuVO> sysMenuVOList=this.sysMenuService.queryAllMenu();
        return new Result<>(sysMenuVOList);
    }

    /**
     *只查询菜单和目录
     *   GET http://127.0.0.1:8080/sysMenu/listMenuMC
     *   接口ID：148742211
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742211
     */
    @GetMapping("listMenuMC")
    @Operation(summary = "查询所有菜单和目录")
    @AppPermission("system:menu:query")
    public Result<List<SysMenuVO>> listMenuMC(){
        List<SysMenuVO> sysMenuVOList=this.sysMenuService.queryAllMenuMC();
        return new Result<>(sysMenuVOList);
    }

    /**
     * 根据菜单ID查询菜单
     *   GET http://127.0.0.1:8080/sysMenu/get/{menuId}
     *   接口ID：148742210
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742210
     */
    @GetMapping("get/{menuId}")
    @Operation(summary = "根据菜单ID查询菜单")
    @AppPermission("system:menu:query")
    public Result<SysMenu> get(@PathVariable Long menuId){
        SysMenu sysMenu=this.sysMenuService.selectByPrimaryKey(menuId);
        return new Result<>(sysMenu);
    }
    /**
     * 添加菜单权限
     *   POST http://127.0.0.1:8080/sysMenu/save
     *   接口ID：148742207
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742207
     */
    @PostMapping("save")
    @Operation(summary = "添加菜单权限")
    @AppPermission("system:menu:add")
    @Log(title = "菜单管理-添加",businessType = BusinessType.INSERT)
    public Result<?> save(@RequestBody @Validated SysMenuAddDTO sysMenuAddDTO){
        int row=this.sysMenuService.insert(sysMenuAddDTO);
        return toAjax(row>0);
    }
    /**
     * 修改菜单权限
     *   PUT http://127.0.0.1:8080/sysMenu/update
     *   接口ID：148742208
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742208
     */
    @PutMapping("update")
    @Operation(summary = "修改菜单权限")
    @AppPermission("system:menu:update")
    @Log(title = "菜单管理-修改",businessType = BusinessType.UPDATE)
    public Result<?> update(@RequestBody @Validated SysMenuUpdateDTO sysMenuUpdateDTO){
        int row=this.sysMenuService.updateByPrimaryKey(sysMenuUpdateDTO);
        return toAjax(row>0);
    }
    /**
     * 删除菜单权限
     *   DELETE http://127.0.0.1:8080/sysMenu/delete/{menuId}
     *   接口ID：148742209
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742209
     */
    @DeleteMapping("delete/{menuId}")
    @Operation(summary = "删除菜单权限")
    @AppPermission("system:menu:remove")
    @Log(title = "菜单管理-删除",businessType = BusinessType.DELETE)
    public Result<?> delete(@PathVariable Long menuId){
        int row=this.sysMenuService.deleteByPrimaryKey(menuId);
        return toAjax(row>0);
    }

    /**
     * 获取动态路由
     *   GET http://127.0.0.1:8080/sysMenu/getRouters
     *   接口ID：148742212
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742212
     */
    @GetMapping("getRouters")
    public Result<List<RouterVO>>  getRouters(){
        List<RouterVO> routerVOList=this.sysMenuService.getRouters();
        return new Result<>(routerVOList);
    }

}
